<template>
  <div class="page-content">
    <dovecote-info></dovecote-info>
    <!-- 选项功能区 -->
    <div class="flex">
      <div>
        <span>鸽龄：</span>
        <el-input-number v-model="form.days" controls-position="right" @change="handleChange" :min="1" :max="99"></el-input-number>
        <span>天</span>
      </div>
      <el-button type="primary" plain @click="openAll">批量亮灯</el-button>
    </div>
    <!--  -->
    <the-table :data="data" :showPage="false" ref="table" :default-sort="{ prop: 'laborTime', order: 'descending' }" @getDataBySelectBox="selectChange">
      <el-table-column type="selection" width="55"/>
      <el-table-column label="鸽笼位置" prop="position" v-if="columns[0].show" sortable/>
      <el-table-column label="更新时间" prop="updateTime" v-if="columns[1].show" sortable/>
       <el-table-column fixed="right" label="操作" width="150px">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-sunny" @click="openLight(scope.row)">
            亮灯
          </el-button>
        </template>
      </el-table-column>
    </the-table>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getRightsByDays } from '@/api/Dovecote/InfoManage/AgeQuery.js'
export default {
  name: "AgeQurey",
  meta: {
    title: "鸽龄查询",
  },
  data() {
    return {
      form: {
        baseId: JSON.parse(window.sessionStorage.getItem("BaseInfo")).id,
        dovecoteNumber: "A01",
        days: 6
      },
      data: [],
      columns: [
        { name: "鸽笼位置", show: true },
        { name: "更新时间", show: true }
      ],
      choosedArray: []
    }
  },
  created() {
    this.init();
  },
  computed: {
    ...mapState({
      dovecoteNumber: state => state.Usersetting.CurrentDovecote.dovecoteNumber
    }),
  },
  watch: {
    dovecoteNumber(val) {
      this.form.dovecoteNumber = val;
      this.init();
    }
  },
  methods: {
    async init() {
      await getRightsByDays(this.form).then(res => {
        console.log(res);
        if(res.data.statusCode === 20000) {
          this.data = res.data.data;
        } else {
          return this.$message.error('获取鸽龄数据错误！')
        }
      })
    },
    handleChange() {
      this.init();
    },
    changeColumn(columns) {
      this.columns = columns
      this.$refs.table.doLayout()
    },
    selectChange(selection) {
      this.choosedArray = selection
    },
    // 亮灯
    openLight() {

    },
    // 批量亮灯
    openAll() {

    }
  }
}
</script>

<style lang="scss" scoped>
.flex {
  display: flex;
  justify-content: space-between;
}
</style>